#ifndef _VIBE_H
#define _VIBE_H

#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/video/video.hpp"

using namespace std;
using namespace cv;

#define VIBE_WIDTH SIZEW_SEARCH//(768) //图像宽
#define VIBE_HEIGHT SIZEH_SEARCH//(1024)//图像高
#define VIBE_FORGROUND_COUNT (20)  //统计前景出现次数，如果超过此次数则把前景更新到背景中
#define MAXIMAGES 20  //一圈最多120张图
#define LAYERS (8+1) //8层背景图 和 1层概率统计图
#define PAI 3.1415926
#define MAXFEATUREPOINTS 200 //特征点个数上限
#define GRADIUS 20 //当前帧与背景模型作差的阈值（可变）
#define GMIN  4 //当前帧与背景模型做差其差值小于20的个数，如果大于等于3则认为是当前像素是背景
#define GVIBERANDOM 255 //vibe子采样率为16
void VibeForground(unsigned char* CurImg, unsigned char* ForImg);
struct backgroundinfo
{
	int valid_flag;
	int layer_no;
	int image_no;
	float servo_yaw;
	float servo_pitch;
	int camera_type;//0红外 1可见光
	float camera_focus;//mm
	int camera_pixelsize;//像元尺寸um
	long long imgID;//图像时间戳信息20220505142108325
	unsigned short img_height;//图像高度
	unsigned short img_wide;//图像宽度
	unsigned char img_bits;//图像位数
	unsigned char img_counter;//图像计数器
	float device_longitude;//经度
	float device_latitude;//纬度
	float device_height;//高度
	unsigned char *y;
	unsigned char *r;
	unsigned char *g;
	unsigned char *b;

};
struct newimginfo
{
	float servo_yaw;
	float servo_pitch;
	float laser_mode;//0关机 1待机 2测距
	float laser_distance;//m
	int camera_type;//0红外 1可见光
	float camera_focus;//mm
	int camera_pixelsize;//像元尺寸um
	long long imgID;//图像时间戳信息20220505142108325
	unsigned short img_height;//图像高度
	unsigned short img_wide;//图像宽度
	unsigned char img_bits;//图像位数
	unsigned char img_counter;//图像计数器
	float device_longitude;//经度
	float device_latitude;//纬度
	float device_height;//高度
	unsigned char *y;
	unsigned char *r;
	unsigned char *g;
	unsigned char *b;
};
struct corners_t
{
	int x;
	int y;
};

void buildfirstloop(struct backgroundinfo * back_ground, struct newimginfo newimg);
void foregroundloop(struct backgroundinfo *back_ground, struct newimginfo newimg, unsigned char* foreimg);
int alignimg(struct backgroundinfo* back_ground, struct newimginfo  newimg, int alignedpixels_x, int alignedpixels_y);
void getAinverse1(int N, double* A, double* invA, int n);
void perspective(int n, struct corners_t* aa, struct corners_t* bb, double * Z);
void CountIntegral(unsigned char* src, unsigned int* dst, int m0, int n0, int size, int width, int height);
void ransac(int k, float sigma, int minlist, struct corners_t* cornersold, struct corners_t* cornersnew, int n, int* list);
int getcorners(unsigned char* img, int w, int h, struct corners_t* corners);
void findpairs(int searchstep, int blockcorr, int w, int h, int N, struct corners_t* cornersnew, struct corners_t* cornersold, unsigned char* imgnew, unsigned char* imgold);
#endif //_VIBE_H

